#include "src/common/cdef.h"
#include "src/Socket/Worker.h"
#include "src/Socket/Socket.h"
#include "src/Socket/Protocol/TCP.h"
#include "src/Socket/Protocol/Text.h"
#include "src/common/function.h"
#include "src/Timer/Timer.h"
int main(int argc, char * argv[]) {
    Socket s = Socket();
    s.initConnectPoll();
    long long client_id = s.connectServer("127.0.0.1", 1029);
    s.setProtocol(new Text());
    s.setCloseHandler([](Connection * client){
        printf("链接关闭\n");
    });
    s.runConnect(true);
    Connection * client = s.getConnectionFormList(&client_id);
    while (true){
        if(client->is_connect){
            break;
        }
    }
    printf("链接成功\n");
    while (true){
        if(!s.checkClientIdIsExist(client_id)){
            printf("链接已被关闭\n");
        }
        char * str_line = new char[200];
        std::cin.getline(str_line, 200);
        BUFF * send_buffer = new BUFF;
        send_buffer->buff = str_line;
        send_buffer->buff_len = strlen(send_buffer->buff);
        s.sendToClient(client_id, send_buffer);
        DEL_BUFF(send_buffer);
    }
}


